#include <iostream>

using namespace std;

const int N = 300;

int n;
char root;
char l[N],r[N];

void dfs(char root){
    cout << root;
    if(l[root] != '*') dfs(l[root]);
    if(r[root] != '*') dfs(r[root]);
}

int main(){
    cin >> n;
    cin >> root;
    cin >> l[root] >> r[root];
    for(int i = 2;i <= n;i++){
        char t; 
        cin >> t;
        cin >> l[t] >> r[t];
    }
    dfs(root);
    return 0;
}
